drop processingdate	// variable for version control only
drop clientid		// single-valued, pretty sure it means us
drop pull			// does not matter in these datasets

* destring IDs. For some, attach names as values. Otherwise, drop names
destring orgid, replace
rename orgid planid

* destring lives variable
destring lives, replace

* format period as a monthly variable
gen m = ym(real(substr(period,1,4)), real(substr(period,-2,2)))
format m %tm
drop period

* there are 4 instances where one of the pull indicates 1 life and the other
* indicates 0 lives. We drop the 0 lives observations in these cases.
duplicates drop

bysort planid m state : gen tot = _N
drop if tot == 2 & lives == 0
drop tot

unique planid state m

* fill in missing months with interpolated lives
egen xID = group(planid state)
xtset xID m
tsfill
gen flag_lives_imput = lives == .

bysort xID (planid) : replace planid = planid[1] if planid == .
bysort xID (state) : replace state = state[_N] if state == ""
drop xID

ipolate lives m, generate(lives_imput) by(planid state)
drop lives
rename lives_imput lives

compress
